<?php
/**
 * 登录设备service
 * @author yupoxiong<i@yupoxiong.com>
 */

declare (strict_types=1);


namespace app\admin\service;


use think\facade\Cache;

class LoginDeviceService extends AdminBaseService
{

    protected string $loginDeviceKey = '_admin_user_current_login_device_id_';

    public function __construct($admin_user)
    {
        $this->loginDeviceKey = getenv('APP_NAME') . $this->loginDeviceKey. $admin_user->id;
    }

    /**
     * 获取当前登录的设备ID
     * @return string
     */
    public function getLoginDeviceId(): string
    {
        return (string)Cache::get($this->loginDeviceKey);
    }

    /**
     * 设置登录的设备ID
     * @param $device_id
     * @return bool
     */
    public function setLoginDeviceId($device_id): bool
    {
        return Cache::set($this->loginDeviceKey, $device_id);
    }

    /**
     * 清除当前登录的设备ID
     * @return bool
     */
    public function clearLoginDeviceId(): bool
    {
        return Cache::delete($this->loginDeviceKey);
    }

}